Skip to content

Conversation

kavon
Copy link
Member

@kavon kavon commented May 30, 2025

This attribute forces programmers to acknowledge every copy that is required in the body of a function. The copies that are "required" to be acknowledged are those that are implicit according to Swift's core language implementation rules. For example,

func consumingFunc(_ t0: consuming Triangle) {}

@_manualOwnership
func basic_function_call(_ t1: Triangle) {
  consumingFunc(t1)  // error: explicit 'copy' required here
}

passing a value to a consuming parameter does not require explicitly copying the argument in the source language, but by the ownership rules a copy will happen. Acknowledging copies does not impact performance and these copies are a superset of all copies that will happen in the function; they are still eligible be eliminated by optimizations.

The way this is implemented is to flag every implicitly-created copy in such functions as an error. This ensures programmers and the compiler are in sync about what copies are actually happening. This motivates performance conscious programmers to write their code in such a way to avoid copies. It also motivates fixes in the compiler for cases where it is emitting a copy that is useless according to the language.

Related to rdar://151323307

@kavon kavon force-pushed the kavon/manual-ownership branch 2 times, most recently from 3e17018 to b6421e4 Compare July 11, 2025 20:04
@kavon kavon force-pushed the kavon/manual-ownership branch from b6421e4 to 3aa5ec5 Compare August 22, 2025 23:25
@kavon kavon force-pushed the kavon/manual-ownership branch 2 times, most recently from 5b6552a to 7a448c0 Compare September 17, 2025 19:05
This attribute forces programmers to acknowledge every
copy that is required to happen in the body of the
function. Only those copies that make sense according
to Swift's ownership rules should be "required".

The way this is implemented as of now is to flag each
non-explicit copy in a function, coming from SILGen, as
an error through PerformanceDiagnostics.
@kavon kavon force-pushed the kavon/manual-ownership branch from 7a448c0 to 61fe8a9 Compare September 17, 2025 20:54
@kavon kavon marked this pull request as ready for review September 17, 2025 21:06
@kavon
Copy link
Member Author

kavon commented Sep 17, 2025

@swift-ci test

@kavon kavon enabled auto-merge September 17, 2025 21:13
@kavon
Copy link
Member Author

kavon commented Sep 17, 2025

16:06:25  error: terminated(127): /tmp/Miscellaneous_TestMultipleFailureSwiftTesting.ZMzkYV/Miscellaneous_TestMultipleFailureSwiftTesting/.build/x86_64-unknown-linux-gnu/Products/Release-linux/TestMultipleFailureSwiftTestingTests-test-runner --dump-tests-json output:
16:06:25  /tmp/Miscellaneous_TestMultipleFailureSwiftTesting.ZMzkYV/Miscellaneous_TestMultipleFailureSwiftTesting/.build/x86_64-unknown-linux-gnu/Products/Release-linux/TestMultipleFailureSwiftTestingTests-test-runner: error while loading shared libraries: TestMultipleFailureSwiftTestingTests.so: cannot open shared object file: No such file or directory

@swift-ci test Linux

@kavon
Copy link
Member Author

kavon commented Sep 18, 2025

@swift-ci smoke test

@kavon
Copy link
Member Author

kavon commented Sep 18, 2025

swiftlang/swift-package-manager#9153

@swift-ci please smoke test Linux

@kavon
Copy link
Member Author

kavon commented Sep 18, 2025

swiftlang/swift-package-manager#9153

@swift-ci please smoke test Windows

@kavon
Copy link
Member Author

kavon commented Sep 18, 2025

Failed on update-checkout...

@swift-ci smoke test windows

@kavon kavon merged commit 84cf0a3 into swiftlang:main Sep 18, 2025
4 of 5 checks passed
@kavon kavon deleted the kavon/manual-ownership branch September 18, 2025 23:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant